package com.zhiqihang.ziqihangservercourse.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName WebConfig
 * @Description Violet
 * @Author 86183
 * @Date 2024/7/4 10:49
 * @Version 1.0
 */
@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")/*允许匹配客户端发过来的任意方法*/
                .allowedMethods("*")/*允许任意请求方法*/
                .allowedHeaders("*")/*允许携带任意请求头*/
                .allowedOriginPatterns("*")/*任意域都可以访问*/
                .allowCredentials(true)/*可以携带会话信息*/
                .maxAge(3600);/*存活时间内再次访问直接放行*/
    }
}
